<%--
  Created by IntelliJ IDEA.
  User: Gao
  Date: 2021/6/8
  Time: 10:50
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ include file="header.jsp"%>
<html>
<head>
    <title>Title</title>
</head>
<body>

    <%--   Ctrl+Shift+/  --%>
   <%-- <table border="1" cellspacing="0" width="400px">
        <tr>
            <td>ID</td>
            <td>名字</td>
            <td>年龄</td>
            <td>性别</td>
        </tr>
        <tr>
            <td>1</td>
            <td>张三</td>
            <td>23</td>
            <td>男</td>
        </tr>
        <tr>
            <td>2</td>
            <td>李四</td>
            <td>23</td>
            <td>男</td>
        </tr>
        <tr>
            <td>3</td>
            <td>王五</td>
            <td>23</td>
            <td>男</td>
        </tr>
    </table>

    <hr/>  --%>
    <a class="layui-btn" href="${pageContext.request.contextPath}/user/getUserInsertPage">添加</a>
    <table border="1" cellspacing="0" width="400px">
        <tr>
            <td>ID</td>
            <td>名字</td>
            <td>年龄</td>
            <td>性别</td>
            <td>删除</td>
        </tr>
        <%-- var:variable 变量
            这个forEach和其他语言的循环遍历是一个意思 for(User user : list){}
            list里面有几个User对象，这个forEach就执行几次，每次输出一行（tr）展示
            这个User的信息
            ArrayList<User> list;
        --%>
        <c:forEach items="${list}" var="user">
            <tr>
                <td>${user.id}</td>
                <td>${user.name}</td>
                <td>${user.age}</td>
                <td>${user.gender}</td>
                <td>
                        <%--  ${pageContext.request.contextPath} 获得项目名字  --%>
                    <%--<a href="${pageContext.request.contextPath}/user/deleteById?id=${user.id}">删除</a>--%>
                    <a href="javascript:deleteById(${user.id})">删除</a>
                </td>
            </tr>
        </c:forEach>
    </table>

   <%-- <script src="/static/jquery/jquery-2.1.4.js" type="text/javascript" charset="utf-8"></script>
    <script src="/static/layer/layer.js" type="text/javascript" charset="utf-8"></script>--%>
    <script>
        function deleteById(id) {
           /* var isDelete = confirm('您确认要删除么？');
            if (isDelete) {// 当用户点击确认之后，才去发送删除操作
                location.href = '${pageContext.request.contextPath}/user/deleteById?id=' + id;
            }*/

            layer.confirm(
                '您确认要删除么?',
                {icon:3, title:'提示'},
                function() {
                    location.href = '${pageContext.request.contextPath}/user/deleteById?id=' + id;
                }
            );
        }
    </script>
</body>
</html>
